#字典
#定义：{ key1:value1,key2:value2}
#注意事项：
#1 key的值不唯一的话，后面的value会替换前面的value 但是不会报错
#2 key的必须是能计算hash的对象，一般是 字符串 或者 数字
# 增 删 改 查
# items()
# keys()
# values()
# clear()
# update()
# len
# 
path1 = '/Users/show/Downloads/编程/python学习/0016_1.txt'
with open(path1,'r',encoding='utf8') as f:
    content1 = f.read().splitlines()
    name_dir = {}
    for i in content1:
        #对每一行的基本处理
        i = i.strip()
        if not i:
            continue

        info =i.split(' ')
        info_list = []
        for j in info:
            if j:
                info_list.append(j)
        #提取姓
        if info_list[0][0] in name_dir:
            name_dir[info_list[0][0]] += int(info_list[1])
        else:
            name_dir[info_list[0][0]] = int(info_list[1])
    for n,m in name_dir.items():
        print(f'{n} : {m}')
    
#
members = {
    1 :{'name':'白月黑羽', 'level':3, 'coins':300},
    2 :{'name':'短笛魔王', 'level':5, 'coins':330},
    3 :{'name':'紫气一元', 'level':6, 'coins':340},
    4 :{'name':'拜月主',   'level':3, 'coins':32200},
    5 :{'name':'诸法空',   'level':4, 'coins':330},
    6 :{'name':'暗光城主', 'level':3, 'coins':320},
    7 :{'name':'心魔尊',   'level':3, 'coins':2300},
    8 :{'name':'日月童子', 'level':8, 'coins':3450},
    9 :{'name':'不死尸王', 'level':3, 'coins':324},
    10:{'name':'天池剑尊', 'level':9, 'coins':13100},
}
menu = '''
请选择操作选项：
   1 查看用户账号信息
   2 添加用户
   3 删除用户
   4 列出所有用户信息
   0 退出
'''
# while True:
#    caozuo =  input(menu)

#    if caozuo == '1':
#         u_id = input('请输入账号名：')
#         if int(u_id) in members:
#             for k,v in members[int(u_id)].items():
#                 print(f'{k}:{v}')
                
#         else:
#             print('用户id不存在，请重新操作')
        
#         continue

#    if caozuo == '2':
#         while True:
#             u_id = input('请输入账户名：')
#             if int(u_id) in members:
#                 print('用户已经存在，请重新输入用户名')
#                 continue
#             break
#         name_info = input('请输入角色名字:')
#         lel_info = input('请输入角色等级：')
#         coins_info = input('请输入角色金币：')
#         info_dir = {}
#         info_dir['name'] = name_info
#         info_dir['level'] = lel_info
#         info_dir['coins'] = coins_info
#         members[u_id] = info_dir
#         continue
   
#    if caozuo == '4':
#         for k,v in members.items():
#             print(f'{k}:{v}')
#         continue
        

#    if caozuo == '3':
#        while True:
#             u_id = input('请输入账户名：')
#             if int(u_id) not in members:
#                 print('用户不存在，请重新输入用户名')
#                 continue
#             break
        
#        members.pop(int(u_id))
#        continue
#    if caozuo == '0':
#        break
   
log_path = '/Users/show/Downloads/编程/python学习/2019-10-22_11.05.40.log'
with open(log_path,'r',encoding='utf8') as f:
    #这里要考虑
    content = f.read().splitlines()

result = {}
for info in content:
    info = info.strip()
    if not info:
        continue
    key_info = info.split('|')
    if key_info[1] in result:
        result[key_info[1]] += 1
    else:
        result[key_info[1]] = 1

for k,v in result.items():
    print(f'{k:25}:{v}个')



##
def get_stock_info(path):
    with open(path,'r',encoding='utf8') as f:
       content =  f.read().splitlines()
    dir1 = {}
    dir2 = {}

    for i in content:
        i = i.strip()
        if not i:
            continue
        name,code = i.split('|')
        dir1[name.strip()] = code
        dir2[code.strip()] = name
    
    return dir1,dir2

path1 = '/Users/show/Downloads/编程/python学习/stock.txt'
dir1,dir2 = get_stock_info(path1)
# while True:
    
#     info = input('请输入要查询的股票名称或代码：')
#     if info.isdigit():
#         if info not in dir2:
#             print('不存在，请重试')
#             continue
#         print(f'{dir2[info]}|{info}')
#     else:
#         if info not in dir1:
#             print('不存在，请重试')
#             continue
#         print(f'{info}|{dir1[info]}')

a_dic = {
    1:2,
    3:4,
    8:4
}
print(a_dic[3])
a_dic['ss'] = 8
# print(a_dic)
# c = a_dic.pop(8)
# print(c)
# print(a_dic)
# del a_dic[1]
# print(a_dic)

for i in a_dic.values():
    print (i)
for j  in a_dic.keys():
    print(j)